#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;

static const char *find_sub_str(const char *s, const char *subs) {
    for (const char *p = s; *p; ++p) {
        bool cmp = true;
        for (const char *tp = p, *ts = subs; *tp && *ts; ++tp, ++ts) {
            if (*tp != *ts) {
                cmp = false;
                break;
            }
        }

        if (cmp)
            return p;
    }

    return 0;
}

static char **split(const char *s, const char *delim) {
    char **res = new char*[1];
    res[0] = 0;

    const size_t sLen = strlen(s);
    const size_t delimLen = strlen(delim);

    const char *beg = s;
    int cnt = 0;
    for (;*beg;) {
        const char *d = find_sub_str(beg, delim);
        if (!d)
            d = s + sLen;

        // creating new string
        char *str = new char[d - beg + 1];
        {
            const char *t = beg; 
            char *tstr = str;
            for (; t != d; ++t, ++tstr)
                *tstr = *t;
            *tstr = 0;

        }

        // inserting new string to result array
        {
            char **nres = new char*[cnt + 2];
            for (int i = 0; i < cnt; ++i)
                nres[i] = res[i];
            nres[cnt] = str;
            nres[cnt+1] = 0;
            res = nres;
            ++cnt;
        }
        //printf("%s\n", str);

        beg = d + delimLen;
    }

    return res;
}

static void delete_string_array(char **ss) {
    if (!ss)
        return;

    for (char **p = ss; *p; ++p)
        delete[] *p;
    delete[] ss;
}

int main() {
    char s[10240];
    char d[1024];
    printf("Enter string:");
    scanf("%s", s);
    printf("Enter delimiter:");
    scanf("%s", d);

    char **ss = split(s, d);
    for (char **p = ss; *p; ++p)
        printf("%s\n", *p);
    delete_string_array(ss);

    return 0;
}
